<template>
  <div class="box">
    <div class="search-box">
      <div class="logo"><img src="../assets/img/logo.png" alt/></div>
      <!--<div class="search">-->
      <!--<input type="text" placeholder="搜艺人"/>-->
      <!--<div class="search_text"><span>搜索</span></div>-->
      <!--</div>-->
      <div>
        <el-dropdown @command="handleCommand">
          <div class="el-dropdown-link userinfo">
            <img src="../assets/mine.png" alt/>
            <div class="user_text">
              <span class="user_name">{{userInfo.realName}}</span>
              <span class="user_phone">{{userInfo.phone}}</span>
            </div>
          </div>
          <el-dropdown-menu slot="dropdown">
            <router-link to="account" v-if="userRole === '2'">
              <el-dropdown-item>个人信息</el-dropdown-item>
            </router-link>
            <router-link to="changepassword" v-if="userRole === '2'">
              <el-dropdown-item>账号中心</el-dropdown-item>
            </router-link>
            <el-dropdown-item command="1">安全退出</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </div>
  </div>

</template>

<script>
  export default {
    data() {
      return {
        activeIndex: "1",
        userInfo: {},
        userRole: ''
      };
    },
    mounted: function () {
      var userRole = sessionStorage.getItem("userrole");
      this.userRole = userRole;
      this.getUserAccountInfo();
    },
    methods: {
      handleSelect() {
      },
      getUserAccountInfo(){
        let self = this;
        let obj = {
          token: self.globalData.token,
        };
        self.$fetch("/User/getUserAccountInfo", obj).then(res => {
          if (res.code === "200") {
            self.globalData.setUserInfo(res.data.userInfo);
            self.userInfo = res.data.userInfo;
          } else {
            self.$message.error(res.message);
          }
        });
      },
      handleCommand(command) {
        this.goLogin();
      },
      goLogin(){
        sessionStorage.clear();
        this.$router.push({path: '/'});
      }
    }
  };
</script>

<style scoped lang="less">
  .box {
    background-color: rgb(50, 50, 50);
  }

  .search-box {
    height: 80px;
    width: 80%;
    margin: auto;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;

    .logo img {
      height: 40px;
      width: auto;
    }
    .search {
      display: flex;
      flex-direction: row;
      align-items: center;
      input {
        width: 200px;
        border-top-left-radius: 20px;
        border-bottom-left-radius: 20px;
        height: 26px;
        padding-left: 16px;
        color: black;
        border: 1px solid white;
        font-size: 12px;
        background-color: #f0f0f0;
        outline: none;
      }
      .search_text {
        background-color: #b3302e;
        height: 30px;
        width: 50px;
        border-top-right-radius: 20px;
        border-bottom-right-radius: 20px;
        display: flex;
        align-items: center;
        justify-content: center;
        span {
          font-size: 12px;
          color: white;
          letter-spacing: 0.6px;
        }
      }
    }
    .userinfo {
      display: flex;
      flex-direction: row;
      align-items: center;
      img {
        width: 30px;
        height: 30px;
      }
      .user_text {
        margin-left: 4px;
        display: flex;
        flex-direction: column;
        font-size: 10px;
        color: #f5f5f5;
      }
    }
  }
</style>
